package com.jn.picasso.presenter;

import android.content.Context;

import com.jn.picasso.contract.MainContract;
import com.jn.picasso.entity.MovieEntity;
import com.jn.picasso.service.MainService;
import com.jn.picasso.utils.FastjsonUtils;
import com.jn.picasso.utils.LogUtils;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainPresenter implements MainContract.IMainPresenter {
    private MainContract.IMainView mMainView;
    private Context mContext;

    public MainPresenter(MainContract.IMainView mMainView, Context mContext) {
        this.mMainView = mMainView;
        this.mContext = mContext;
    }

    @Override
    public void getData() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.oioweb.cn/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        MainService mainService = retrofit.create(MainService.class);
        mainService.getData().enqueue(new Callback<MovieEntity>() {
            @Override
            public void onResponse(Call<MovieEntity> call, Response<MovieEntity> response) {
                MovieEntity movie = response.body();
                mMainView.showData(movie);
            }

            @Override
            public void onFailure(Call<MovieEntity> call, Throwable throwable) {

            }
        });

    }
}
